/**
 * Copyright (C), 2015-2020, XXX有限公司
 * FileName: BusCollectActivity
 * Author: Clark
 * Date: 2020/10/10 21:01
 * Description:
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */
package sz.szsmk.citizencard.ui.activity;

import android.os.Build;
import android.util.Log;
import android.view.View;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import com.chenenyu.router.annotation.Route;

import java.util.ArrayList;
import java.util.List;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.ActivityCollectionlistBinding;
import sz.szsmk.citizencard.ioc.Compontent.DaggerCommonActivityComponent;
import sz.szsmk.citizencard.mvp.contract.ISimpleContact;
import sz.szsmk.citizencard.mvp.presenter.SimplePresenter;
import sz.szsmk.citizencard.ui.adapter.BusCollectFragmentAdapter;
import sz.szsmk.citizencard.ui.base.IBaseActivity;
import sz.szsmk.citizencard.ui.fragment.BusCollecLineFragment;
import sz.szsmk.citizencard.ui.fragment.BusHomeSiteCollecFragment;

/**
 * @ClassName: BusCollectActivity
 * @Description:
 * @Author: Clark
 * @Date: 2020/10/10 21:01
 */
@RequiresApi(api = Build.VERSION_CODES.M)
@Route("busCollectActivity")
public
class BusCollectActivity extends IBaseActivity<SimplePresenter, ActivityCollectionlistBinding> implements ISimpleContact.ISimpleView, ViewPager2.OnScrollChangeListener, View.OnClickListener {


    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_collectionlist;
    }

    @Override
    protected void initInjector() {
        DaggerCommonActivityComponent.builder().appCompontent(DaggerApplication.getAppComponent())
                .build().inject(this);
    }

    @Override
    protected void initViews() {

        dataBinding.backLayout.settingTitle.setText("收藏夹");
        dataBinding.backLayout.back.setOnClickListener(this);
        List<Fragment> mFragments=new ArrayList<>();
        mFragments.add(new BusCollecLineFragment());
        mFragments.add(new BusHomeSiteCollecFragment());
        BusCollectFragmentAdapter busCollectFragmentAdapter=new BusCollectFragmentAdapter(this,mFragments);
        dataBinding.viewPager.setAdapter(busCollectFragmentAdapter);
        dataBinding.busHomeXl.setOnClickListener(this);
        dataBinding.viewPager.setOnScrollChangeListener(this);
        dataBinding.busHomeZd.setOnClickListener(this);
        dataBinding.viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                super.onPageScrolled(position, positionOffset, positionOffsetPixels);
            }

            @Override
            public void onPageSelected(int position) {
                if(position==0){
                    dataBinding.suggestLine1.setVisibility(View.VISIBLE);
                    dataBinding.suggestLine2.setVisibility(View.GONE);
                }else {
                    dataBinding.suggestLine1.setVisibility(View.GONE);
                    dataBinding.suggestLine2.setVisibility(View.VISIBLE);
                }

                super.onPageSelected(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {
                super.onPageScrollStateChanged(state);
            }
        });
    }

    @Override
    protected void updateViews() {

    }

    @Override
    public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {

        Log.d("clark",v.toString()+scrollX+scrollY+oldScrollX+oldScrollY+" ");

    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.bus_home_xl) {
            dataBinding.suggestLine1.setVisibility(View.VISIBLE);
            dataBinding.suggestLine2.setVisibility(View.GONE);
            dataBinding.viewPager.setCurrentItem(0);
        } else if (id == R.id.bus_home_zd) {
            dataBinding.suggestLine1.setVisibility(View.GONE);
            dataBinding.suggestLine2.setVisibility(View.VISIBLE);
            dataBinding.viewPager.setCurrentItem(1);
        } else if (id == R.id.back) {
            finish();
        }
    }
}